package cn.wolfcode.web.controller;


import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.qo.SystemDictionaryItemQueryObject;
import cn.wolfcode.service.SystemDictionaryItemService;
import cn.wolfcode.service.SystemDictionaryService;
import cn.wolfcode.vo.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/systemDictionaryItem")
public class SystemDictionaryItemController {

    @Autowired
    private SystemDictionaryItemService systemDictionaryItemService;

    @Autowired
    private SystemDictionaryService systemDictionaryService;


    @RequiresPermissions(value = {"systemDictionaryItem:list", "字典明细表页面"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") SystemDictionaryItemQueryObject qo) {
        PageInfo<SystemDictionaryItem> pageInfo = systemDictionaryItemService.selectBySdId(qo);
        List<SystemDictionary> systemDictionaries = systemDictionaryService.listAll();

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("systemDictionaries", systemDictionaries);

        return "systemDictionaryItem/list";
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = {"systemDictionaryItem:delete", "字典明细表删除"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult delete(Long id) {
        if (id != null) {
            systemDictionaryItemService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"systemDictionaryItem:saveOrUpdate", "字典明细表新增/编辑"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(SystemDictionaryItem systemDictionaryItem) {

        systemDictionaryItemService.saveOrUpdate(systemDictionaryItem);

        return new JsonResult();


    }

}
